package classes;

import java.util.ArrayList;
import com.dcdrake.testApp.R;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class EventArrayAdapter extends ArrayAdapter<Event>{
	
	private final Context context;
	private ArrayList<Event> list;
	private Event event;
	final String debugTAG = "debug";
	
	public EventArrayAdapter(Context context, ArrayList<Event> list){
		super(context, R.layout.rowlayout); 
		this.context = context;
		this.list = list;
	}

	//Defaults to zero, meaning the adapter thinks there are no items to be displayed. It must return the length of the list.
	@Override
	public int getCount() {
		return list.size();
	}

	//Called whenever there is a change to the view
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
		TextView textViewName = (TextView) rowView.findViewById(R.id.name);
		TextView textViewDate = (TextView) rowView.findViewById(R.id.date);
		TextView textViewLocation = (TextView) rowView.findViewById(R.id.location);
		Log.v(debugTAG, "Found all textViews");


		event = list.get(position);
		Log.v(debugTAG, "got event from list");

		textViewName.setText(event.getName());
		Log.v(debugTAG, "Added event name to textView");

		textViewDate.setText(event.getMonth() + "." + event.getDay() + "." + event.getYear());
		Log.v(debugTAG, "Added event date to textView");

		textViewLocation.setText(event.getLocation());
		Log.v(debugTAG, "Added event location to textView");

		return rowView;
	}
}
